﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DotConferenceSql;
using NUnit.Framework;
using NUnit.Framework.SyntaxHelpers;

namespace TestDotConferenceSql
{
    [TestFixture]
    public class TestSelectQueryElement
    {
        SqlQuery query;

        [SetUp]
        public void Init()
        {
            query = new SqlQuery();

            query.Elements.Add(new FromTableQueryElement("Test"));
        }

        [Test]
        public void BasicSelectQuery()
        {
            SelectQueryElement selectElement = new SelectQueryElement();
            selectElement.Add("field");

            query.Elements.Add(selectElement);

            Assert.That(query.BuildTextQuery(), Text.Contains("SELECT field FROM Test"));
        }

        [Test]
        public void SelectWithAddRangeQuery()
        {
            SelectQueryElement selectElement = new SelectQueryElement();
            selectElement.AddRange(new string[] { "field1", "field2", "field3" });

            query.Elements.Add(selectElement);
            
            Assert.That(query.BuildTextQuery(), Text.Contains("SELECT field1,field2,field3 FROM Test"));
        }

        [Test]
        public void SelectWithNoField()
        {
            SelectQueryElement selectElement = new SelectQueryElement();

            query.Elements.Add(selectElement);

            Assert.That(query.BuildTextQuery(), Text.Contains("SELECT * FROM Test"));
        }
    }
}
